{ Russian Olympiad. 2 stage.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/roi/stage2/roi_2stage.pdf
  Problem 1
  Points: 100
}
{$APPTYPE CONSOLE}
var n,s,max:int64; a,prost:array[0..1000001] of int64; i,j:longint;
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
readln(n);
fillchar(prost,sizeof(prost),0);
max:=0;
for i:=1 to n do begin
  read(a[i]);
  if a[i]>max then max:=a[i];
end;
for I := 2 to max do begin
  if prost[i]=0 then begin
    prost[i]:=1;
    j:=i+i;
    while (j<=max) do begin
      prost[j]:=2;
      inc(j,i);
    end;
  end;
end;
for i := 1 to n do if prost[a[i]]=1 then begin
  write(a[i],' ');
  a[i]:=0;
end;
for i := 1 to n do if (prost[a[i]]=2) and (a[i]<>0) then write(a[i],' ');
close(input);
close(output);
end.
